<template>
  <div class="mine">
    <div class="header">
      <div class="headImage"></div>
      <p class="telephone">{{ tele }}</p>
    </div>

    <div
      class="lineBlock"
      v-for="item in mineData"
      :key="item.id"
      @click="toChild(item.id)"
    >
      <van-cell :title="item.title" :icon="item.icon">
        <!-- 使用 right-icon 插槽来自定义右侧图标 -->
        <template #right-icon>
          <van-icon :name="bigerUrl" class="search-icon" />
        </template>
      </van-cell>
    </div>
    <router-view></router-view>
  </div>
</template>

<script>
import { getMineData } from '@/api/mine.js'
export default {
  name: 'Mine',
  data() {
    return {
      mineData: null,
      bigerUrl: null,
      headBack: null,
      tele: null
    }
  },
  created() {
    if (localStorage.getItem('Token')) {
      getMineData().then(res => {
        this.mineData = res.data.data
        this.bigerUrl = res.data.biggerIcon
        this.headBack = res.data.head.backgroundUrl
        this.tele = JSON.parse(localStorage.getItem('Token')).tele
      })
    } else {
      this.$router.push('/login')
    }
  },
  methods: {
    toChild(id) {
      switch (id) {
        case 0:
          this.$router.push({ name: 'MySend', params: { tele: this.tele } })
          break
        case 1:
          this.$router.push({ name: 'MyLocation', params: { tele: this.tele } })
          break
        case 2:
          this.$router.push({ name: 'Suggest', params: { tele: this.tele } })
          break
        case 3:
          this.$router.push({ name: 'MyInfo', params: { tele: this.tele } })
          break
        case 4:
          this.$router.push({ name: 'RealName', params: { tele: this.tele } })
          break
      }
    }
  }
}
</script>

<style lang="less" scoped>
.mine {
  height: 100%;
  background: #ecf3ff;
}
.header {
  height: 10rem;
  width: 100%;
  margin-bottom: 1rem;
  padding-top: 1.7rem;
  background-image: url(https://m.zto.com/static/images/member/bg.jpg);
  background-size: 100% 100%;
}
.search-icon {
  font-size: 16px;
  line-height: inherit;
}

.headImage {
  margin: 0 auto;
  width: 4.5rem;
  height: 4.5rem;

  border-radius: 50%;
  background-color: #fff;
  background-image: url(https://libs.zto.cn/weixin_images/header.png);
  background-size: 100% 100%;
}
.telephone {
  text-align: center;
  color: #fff;
  font-size: 0.8rem;
}

.lineBlock {
  border-bottom: 1px solid #e5e5e5;
  font-size: 1rem;
  img {
    width: 1.3rem;
    height: 1.3rem;
  }
  span {
    font-size: 1rem;
    margin-left: 0.5rem;
  }
  &:nth-child(4) {
    margin-bottom: 1rem;
    border: none;
  }
  &:last-child {
    border: none;
  }
}
</style>
